﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QuanLyDiemSinhVien.Manager;

namespace QuanLyDiemSinhVien.Resources.Form
{
    public partial class MainForm : XtraForm
    {
        public MainForm()
        {
            InitializeComponent();
            gridControl1.DataSource = GetDatasource(50);
        }

        private static DataTable GetDatasource(int total)
        {
            Random random = new Random(10);
            DataTable table = new DataTable("SinhVien");
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Hoten", typeof(string));
            table.Columns.Add("Ngaysinh", typeof(DateTime));
            table.Columns.Add("Diemmon1", typeof(float));
            table.Columns.Add("Diemmon2", typeof(float));
            table.Columns.Add("Diemmon3", typeof(float));
            table.Columns.Add("Diemtongket", typeof(float));

            for (int i = 0; i < total; i++)
            {
                
                DataRow row = table.NewRow();
                row["ID"] = i;
                row["Hoten"] = string.Format("Nguyen Van A {0}", i);
                row["Ngaysinh"] = DateTime.Now.AddYears(-19);
                row["Diemmon1"] = random.Next(1, 10);
                row["Diemmon2"] = random.Next(1, 10);
                row["Diemmon3"] = random.Next(1, 10);
                row["Diemtongket"] = Convert.ToDecimal(row["Diemmon1"] = random.Next()) + Convert.ToDecimal(row["Diemmon2"] = random.Next()) + Convert.ToDecimal(row["Diemmon3"] = random.Next());
                table.Rows.Add(row);
            }
            return table;
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                Random ran = new Random();
                gridControl1.DataSource = GetDatasource(ran.Next(20, 50));
            }
            catch (Exception)
            {

            }
        }

        private void btnKetNoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                var connectConfig = new ConnectConfig();
                connectConfig.Show();
                Hide();
            }
            catch (Exception ex)
            {
                
                
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void btnKetThuc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Application.Exit();
        }
    }
}